// 展示录制的命令
const handleMessage = (function () {
    let content = document.getElementById('content');
    let circle = document.getElementById('circle');
    let img = document.getElementById('ide-img');
    img.src = (window.chrome ? chrome : browser).runtime.getURL('/icons/icon_light128.png');
    let lastTimeoutHandle = 0;

    function resetContent() {
        content.innerText = '录制中...';
        content.setAttribute('aria-label', '录制中...');
        content.setAttribute('role', 'alert');
        content.style.color = '#E80600';
        circle.style.animation = 'fadeIn 1s infinite alternate';
        circle.style.visibility = 'visible';
    }
    return function (event) {
        if (event.data && event.data.direction === 'from-recording-module') {
            clearTimeout(lastTimeoutHandle);
            content.innerText = 'Recorded ' + event.data.command;
            content.style.color = '#114990';
            circle.style.animation = 'none';
            circle.style.visibility = 'hidden';
            lastTimeoutHandle = setTimeout(resetContent, 1000);
        }
    };
})();
window.addEventListener('message', handleMessage);
